﻿#include "BaseKit.h"
#include "IndexController.h"
#include "HomeController.h"
#include "TransactionController.h"
#include "MessageController.h"
#include "OurController.h"

static RootWindow* rootWindow=nullptr;

RootWindow::RootWindow():navigation(nullptr){}

RootWindow::~RootWindow(){}

bool RootWindow::init(){
	if(!CAWindow::init()){
		return false;
	}
	font.fontSize=30;
	font.color=ccc4(102, 102, 102, 255);

	CANavigationController* home=new CANavigationController();
	home->setNavigationBarHidden(true, false);
	home->initWithRootViewController(HomeController::create());
	home->setTabBarItem(CATabBarItem::create("首页", CAImage::create("img/home_gray.png"), CAImage::create("img/home_green.png")));
	home->autorelease();
	CANavigationController* transaction=new CANavigationController();
	transaction->setNavigationBarHidden(true, false);
	transaction->initWithRootViewController(TransactionController::create());
	transaction->setTabBarItem(CATabBarItem::create("交易大厅", CAImage::create("img/transaction_gray.png"), CAImage::create("img/transaction_green.png")));
	transaction->autorelease();
	CANavigationController* message=new CANavigationController();
	message->setNavigationBarHidden(true, false);
	message->initWithRootViewController(MessageController::create());
	message->setTabBarItem(CATabBarItem::create("消息", CAImage::create("img/message_gray.png"), CAImage::create("img/message_green.png")));
	message->autorelease();
	CANavigationController* our=new CANavigationController();
	our->setNavigationBarHidden(true, false);
	our->initWithRootViewController(OurController::create());
	our->setTabBarItem(CATabBarItem::create("我的", CAImage::create("img/our_gray.png"), CAImage::create("img/our_green.png")));
	our->autorelease();
	CAVector<CAViewController*> views;
	views.pushBack(home);
	views.pushBack(transaction);
	views.pushBack(message);
	views.pushBack(our);
	views.autorelease();
	CATabBarController* bar=new CATabBarController();
	bar->initWithViewControllers(views);
	bar->setTabBarBackgroundImage(CAImage::createWithColor4B(ccc4(77, 77, 77, 16)));
	bar->setTabBarSelectedBackgroundImage(CAImage::createWithColor4B(ccc4(77, 77, 77, 16)));
	bar->setTabBarTitleColorForSelected(themeColor);
	bar->setTabBarTitleColorForNormal(CAColor4B::BLACK);
	bar->autorelease();
	navigation=new CANavigationController();
	navigation->initWithRootViewController(bar);
	navigation->setNavigationBarHidden(true, false);
	navigation->autorelease();
	this->setRootViewController(navigation);

	return true;
}

RootWindow* RootWindow::getInstance(){
	if(rootWindow==nullptr){
		rootWindow=new RootWindow();
		rootWindow->init();
	}

	return rootWindow;
}

void RootWindow::destroyInstance(){
	CC_SAFE_DELETE(rootWindow);
	rootWindow=nullptr;
}